import 'package:flutter/material.dart';
import './ProductCard.dart';

import 'package:scoped_model/scoped_model.dart';
import '../../Models/banner.dart';
import '../../ScopedModels/ScopedMain.dart';
class Products extends StatelessWidget {
 @override
  Widget build(BuildContext context) {
    print('[Products Widget] build');
    // TODO: implement build
    return ScopedModelDescendant<ScopedMain>(
      //数据改变时调用 
        builder: (BuildContext context, Widget child, ScopedMain model) {
      return _buildProductList(model.banners);
    });
  }

  Widget _buildProductList(List<HomeBanner> banners) {
    Widget productList;
    if (banners.length > 0) {
      productList = ListView.builder(
        itemBuilder: (BuildContext context, int index) =>
            ProductCard(banners[index],index),
        itemCount: banners.length,
      );
    } else {
      
    }
    return productList;
  }
  
}
